package com.zuipin.controller;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.zuipin.framework.annotation.Inject;
import com.zuipin.framework.annotation.Valid;
import com.zuipin.framework.annotation.Valids;
import com.zuipin.framework.result.Result;
import com.zuipin.service.INewsInfoService;
import com.zuipin.util.Pagination;
import com.zuipin.util.RegexUtils;
import com.zuipin.vo.BackNewsInfoDetailVo;
import com.zuipin.vo.BackNewsInfoVo;
import com.zuipin.vo.NewsInfoListVo;
import com.zuipin.vo.NewsInfoSearchVo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import springfox.documentation.annotations.ApiIgnore;

@Api(value = "新闻信息", description = "新闻信息-zhouhuihang")
@RestController
@RequestMapping(value = "/newsInfo")
public class NewsInfoController {
	@Resource
	private INewsInfoService	newsInfoService;
	
	private static Logger		log	= LoggerFactory.getLogger(NewsInfoController.class);
	
	@RequestMapping(value = "/searchNewsInfoAllByBack", method = RequestMethod.GET)
	@ApiOperation(value = "(后台)查询全部新闻信息", notes = "六期(后台)查询全部新闻信息-zhouhuihang")
	@Valids({ @Valid(name = "search.sysId", required = true), //
			@Valid(name = "search.newsStatus", required = false, regex = "0|1"), //
			@Valid(name = "search.endCreatedTime", required = false, regex = RegexUtils.DATE_TIME_FORMAT2), //
			@Valid(name = "search.beginCreatedTime", required = false, regex = RegexUtils.DATE_TIME_FORMAT2), })
	@ApiImplicitParams({ @ApiImplicitParam(name = "search.sysId", value = "系统Id", required = true, dataType = "long", paramType = "query"), //
			@ApiImplicitParam(name = "search.mainTitle", value = "标题", required = false, dataType = "string", paramType = "query"), //
			@ApiImplicitParam(name = "search.endCreatedTime", value = "结束注册时间", required = false, dataType = "string", paramType = "query"), //
			@ApiImplicitParam(name = "search.beginCreatedTime", value = "开始注册时间", required = false, dataType = "string", paramType = "query"), //
			@ApiImplicitParam(name = "search.newsStatus", value = "新闻状态 1：显示: 0：隐藏'", required = false, dataType = "integer", paramType = "query"), //
			@ApiImplicitParam(name = "search.newsTypeIds", value = "类别Ids（用,隔开）", required = false, dataType = "string", paramType = "query"), //
			@ApiImplicitParam(name = "search.taggingIds", value = "标注Ids（用,隔开）", required = false, dataType = "string", paramType = "query"), //
			@ApiImplicitParam(name = "page.pageSize", value = "pageSize", required = false, dataType = "integer", paramType = "query"), //
			@ApiImplicitParam(name = "page.pageNumber", value = "pageNumber", required = false, dataType = "integer", paramType = "query"), })
	public Result<List<BackNewsInfoVo>> searchNewsInfoAllByBack(@Inject @ApiIgnore NewsInfoSearchVo search, @Inject @ApiIgnore Pagination page) {
		return newsInfoService.searchNewsInfoAllByBack(search, page);
	}
	
	@RequestMapping(value = "/creatAndUpdateNewsInfo", method = RequestMethod.POST)
	@ApiOperation(value = "(后台)新增(修改)新闻", notes = "六期(后台)新增(修改)新闻-zhouhuihang")
	@Valids({ @Valid(name = "newsInfoDetail.mainTitle", required = true, maxLength = 50), //
			@Valid(name = "newsInfoDetail.remark", required = false, maxLength = 100), //
			@Valid(name = "newsInfoDetail.newsTypeId", required = true), //
			@Valid(name = "newsInfoDetail.newsInfoImgs.type", required = false, regex = "COVER|MAIN|SUB"),
			@Valid(name = "newsInfoDetail.newsInfoImgs.delFlag", required = false, regex = "0|1") })
	public Result creatAndUpdateNewsInfo(@RequestBody @ApiParam BackNewsInfoDetailVo newsInfoDetail) {
		if (newsInfoDetail.getId() == null) {
			return newsInfoService.creatNewsInfo(newsInfoDetail);
		} else {
			return newsInfoService.updateNewsInfo(newsInfoDetail);
		}
	}
	
	@RequestMapping(value = "/findNewsInfoDetail", method = RequestMethod.GET)
	@ApiOperation(value = "(后台)查看新闻详情", notes = "六期(后台)查看新闻详情-zhouhuihang")
	@Valids({ @Valid(name = "sysId", required = true), //
			@Valid(name = "id", required = true), })
	@ApiImplicitParams({ @ApiImplicitParam(name = "sysId", value = "系统ID", required = true, dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "id", value = "新闻ID", required = true, dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "isIncreaseRealNum", value = "是否增加真实阅读量[0:否，1：是]", required = false, dataType = "short", paramType = "query"), })
	public Result<BackNewsInfoDetailVo> findNewsInfoDetail(@RequestParam(required = true) Long sysId, @RequestParam(required = true) Long id,
			@RequestParam(required = false) Short isIncreaseRealNum) {
		return newsInfoService.findNewsInfoDetail(sysId, id, isIncreaseRealNum);
	}
	
	@RequestMapping(value = "/getNewsInfoList", method = RequestMethod.GET)
	@ApiOperation(value = "(前台)查看新闻列表", notes = "(前台)查看新闻列表-zhouhuihang")
	@Valids({ @Valid(name = "sysId", required = true), @Valid(name = "hotNewsTag", required = false, regex = "0|1"), })
	@ApiImplicitParams({ @ApiImplicitParam(name = "hotNewsTag", value = "是否热门资讯 0:非热讯 1：热讯", required = false, dataType = "integer", paramType = "query"), //
			@ApiImplicitParam(name = "newsTypeId", value = "类别Id(类别：15[400:送礼锦囊,401:选茶锦囊,402:新闻头条]", required = false, dataType = "long", paramType = "query"), //
			@ApiImplicitParam(name = "sysId", value = "系统Id", required = true, dataType = "long", paramType = "query"), //
			@ApiImplicitParam(name = "taggingId", value = "标注Id(标注：16[403:送父母,404:送领导,405:送客户,406:送好友,407:送导师,408:送同事]", required = false, dataType = "long", paramType = "query"), //
			@ApiImplicitParam(name = "page.pageSize", value = "pageSize", required = false, dataType = "integer", paramType = "query"), //
			@ApiImplicitParam(name = "page.pageNumber", value = "pageNumber", required = false, dataType = "integer", paramType = "query"), })
	public Result<List<NewsInfoListVo>> getNewsInfoList(Long sysId, Integer hotNewsTag, Long newsTypeId, Long taggingId, @Inject @ApiIgnore Pagination page) {
		return newsInfoService.getNewsInfoList(sysId, hotNewsTag, newsTypeId, taggingId, page);
	}
	
	@RequestMapping(value = "/modifyNewsInfoStatus", method = RequestMethod.POST)
	@ApiOperation(value = "显示|隐藏新闻", notes = "显示|隐藏新闻-zhouhuihang")
	@Valids({ @Valid(name = "id", required = true), @Valid(name = "newsStatus", required = true, regex = "0|1"), })
	@ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "新闻ID", required = true, dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "newsStatus", value = "状态  1：显示: 0：隐藏", required = true, dataType = "integer", paramType = "query"), })
	public Result modifyNewsInfoStatus(Long id, Integer newsStatus) {
		return newsInfoService.modifyNewsInfoStatus(id, newsStatus);
	}
	
}
